package com.mvc.controller;

import com.alibaba.fastjson.JSON;
import com.mvc.entity.Order;
import com.mvc.entity.OrderItem;
import com.mvc.model.Result;
import com.mvc.service.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName OrderItemController
 * @Description TODO
 * @Author Gla
 * @Date 2021/12/2 10:00
 * @Version 1.0
 **/
@Controller
@RequestMapping(value = "/orderItem", produces = "text/html;charset=UTF-8")
public class OrderItemController {
    @Autowired
    private OrderItemService orderItemService;

    @RequestMapping(value = "/search.do")
    @ResponseBody
    public String listSearch(@RequestParam Integer page, @RequestParam Integer limit,
                             @RequestParam Integer orderId){

        Integer startRow = (page - 1) * limit;

        List<OrderItem> list = orderItemService.listSearch(startRow,limit,orderId);
        Integer count = orderItemService.getCount(orderId);

        Result result = new Result();
        result.setCode(0);
        result.setCount(count);
        result.setData(list);
        String s = JSON.toJSONString(result);
        return s;
    }
}
